﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Cloak.Reflection;

namespace Cloak.Mvp.Autofac.ViewParameters
{
	/// <summary>
	/// A check that constructor parameters are decorated with <see cref="ViewAttribute"/>
	/// </summary>
	public sealed class ViewParameterAttributedSpecification : IViewParameterSpecification
	{
		/// <summary>
		/// Determines if the specified parameter is a constructor parameter decorated with <see cref="ViewAttribute"/>
		/// </summary>
		/// <param name="parameter">The parameter to check for representing a view</param>
		/// <returns>
		/// Whether the specified parameter is a constructor parameter decorated with <see cref="ViewAttribute"/>
		/// </returns>
		public bool IsView(ParameterInfo parameter)
		{
			var viewAttribute = parameter.GetAttribute<ViewAttribute>();

			return parameter.Member is ConstructorInfo && viewAttribute != null && viewAttribute.IsView;
		}
	}
}